package com.psychproject.web.helpers;

public class PageHelper {
	private static final int PAGE_SIZE = 3;
	private int page;
	private int totalNum;
	private int totalPages;
	private int start;
	private int end;
	private String pageUrl;

	public PageHelper(int page, int totalNum, String pageUrl) {
		super();
		this.page = page;
		this.totalNum = totalNum;
		this.totalPages = (totalNum - 1) / PAGE_SIZE + 1;
		this.start = (page - 1) * PAGE_SIZE;
		this.end = Math.min(this.start + PAGE_SIZE, totalNum);
		this.pageUrl = pageUrl;
	}

	public boolean hasPre() {
		return page > 1;
	}

	public boolean hasNext() {
		return page < totalPages;
	}

	public int getPage() {
		return page;
	}

	public int getTotalNum() {
		return totalNum;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public int getStart() {
		return start;
	}

	public int getEnd() {
		return end;
	}

	public int getPageSize() {
		return PAGE_SIZE;
	}

	public String getHtmlPager() {
		String pageer = "<script type='text/javascript'>var var_curPage ="
				+ page + ";var var_totalPage=" + totalPages
				+ ";var var_pageUrl = '" + pageUrl + "';</script>";
		pageer += "<div id='pagintor'></div>";
		return pageer;
	}
}
